package com.vincent.kdp.js;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.util.Log;
import android.webkit.JavascriptInterface;
import android.widget.Toast;

import com.vincent.baseapp.util.SPUtil;
import com.vincent.kdp.Activity.QualitypolicyActivity;
import com.vincent.kdp.ui.commodity.repository.CommodityDetailRepository;
import com.vincent.kdp.ui.other.MainActivity;
import com.vincent.kdp.util.BaseParam;

/**
 * Created by pg on 2017/1/23.
 */

public class AddConsumeOperator {

    private Activity activity;
    private String type;
    private String name;
    private String barCode;
    private String price;
    private String weight;
    private String phone;
    private String deposit;
    private CommodityDetailRepository repository = new CommodityDetailRepository();

    public AddConsumeOperator(Activity activity, String type, String barCode, String name, String price
    ,String weight,String phone,String deposit) {
        this.activity = activity;
        this.type = type;
        this.name = name;
        this.barCode = barCode;
        this.price = price;
        this.weight = weight;
        this.phone = phone;
        this.deposit = deposit;
        Log.i("code", name + "----" + barCode + "----" + price);
    }

    @JavascriptInterface
    public String getDeviceId() {
        return BaseParam.getDeviceId();
    }

    @JavascriptInterface
    public String getBarCode() {
        return barCode;
    }

    @JavascriptInterface
    public String getName() {
        return name;
    }

    @JavascriptInterface
    public String getPrice() {
        return price;
    }

    @JavascriptInterface
    public String shoppingIds() {
        return "";
    }

    @JavascriptInterface
    public String getEmpId() {
        return SPUtil.getString("empId");
    }

    @JavascriptInterface
    public String getEmpName() {
        return SPUtil.getString("name");
    }


    @JavascriptInterface
    public String getTotalWeight() {

        return weight;
    }

    @JavascriptInterface
    public String getPhone() {
        return phone;
    }

    @JavascriptInterface
    public String getDeposit() {

        return deposit;
    }


    @JavascriptInterface
    public void getWebId(final String message, final String url) {
        activity.runOnUiThread(new Runnable() {
            @Override
            public void run() {
                Log.i("code", message);
                if ("请求成功".equals(message)) {
                    Toast.makeText(activity, url, Toast.LENGTH_SHORT).show();
                    //MainActivity.reload=1;
                    Intent intent = new Intent(activity, QualitypolicyActivity.class);
                    intent.putExtra("barCode", barCode);
                    intent.putExtra("url", url);
                    activity.startActivity(intent);

                }
            }
        });

    }

}
